package Test;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

@WebServlet("/readmdTest")
public class ReadmdTest extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String savePath = request.getServletContext().getRealPath("/md");  //存储路径
        String fileName = savePath+"/1705232358618.md";
        // java 11 开始提供的方法，读取文件不能超过2G，与你的内存息息相关
        String s = Files.readString(Paths.get(fileName));
        System.out.println(s);
        HttpSession session=request.getSession();
            session.setAttribute("aaa", s);
            response.sendRedirect("./WinterTourism/material/articleDetails.jsp");
        /*
        *
        *  byte[] bytes = Files.readAllBytes(Paths.get(fileName));
        * String content = new String(bytes, StandardCharsets.UTF_8);
        * System.out.println(content);*/


    }
}
